/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package demo1022;

import demo1021.*;
import java.sql.*;
import javax.swing.JOptionPane;

/**
 *
 * @author Administrator
 */
public class LoginDemno1 {

    public static void main(String args[]) {
        Connection conn = null;
        PreparedStatement pstat = null;
        ResultSet rs = null;
        try {
            Class.forName("com.mysql.jdbc.Driver");//
            String url = "jdbc:mysql://localhost:3306/st?characterEncoding=gbk";
            conn = DriverManager.getConnection(url, "root", "");
            pstat = conn.prepareStatement("select password,username from user"
                    + " where username=?  ");
            String name = JOptionPane.showInputDialog("input name");
            String pass = JOptionPane.showInputDialog("input password");
            pstat.setString(1, name);
            rs = pstat.executeQuery();
            if (rs.next()) {
                if (pass.equals(rs.getString(1))) {
                    JOptionPane.showMessageDialog(null, "登陆成功 ");
                } else {
                    JOptionPane.showMessageDialog(null, "密码错误 ");
                }
            } else {
                JOptionPane.showMessageDialog(null, "用户名错误");
            }
        } catch (ClassNotFoundException e) {
            System.out.println(e.getMessage());
        } catch (SQLException e) {
            System.out.println(e.getMessage());

        }


    }
}
